import _fetch from './requset'
import axios from 'axios'
let _cancel = ''
function articlesTechnic (params) {
  return _fetch({
    url: '/articles/technic',
    params: params
  })
}
function chartDatHhot () {
  return _fetch({
    url: '/chart-data/hot'
  })
}
function articlesShare (params) {
  try {
    _cancel()
  } catch {}
  return _fetch({
    url: '/articles/share',
    params,
    cancelToken: new axios.CancelToken(cancel => {
      // cancel取消接口
      _cancel = cancel
    })
  })
}
// 面经热搜
function articlesTechnicTopSearch () {
  return _fetch({
    url: '/articles/technicTopSearch'
  })
}
// 文章详情
function articlesShareId (id) {
  return _fetch({
    url: '/articles/share/' + id
  })
}
// 面经评论
function articlesCommentsId (id, params) {
  return _fetch({
    url: '/articles/comments/' + id,
    params
  })
}
// 面经发表评论
function articlesComments (data) {
  return _fetch({
    url: '/articles/comments',
    needToken: true,
    method: 'post',
    data
  })
}
// 面经收藏
function articlesCollect (data) {
  return _fetch({
    url: '/articles/collect',
    method: 'post',
    needToken: true,
    data
  })
}
// 面经文章点赞
function articlesStar (data) {
  return _fetch({
    url: '/articles/star',
    method: 'post',
    needToken: true,
    data
  })
}
// 评论点赞
function articleCommentsStar (data) {
  return _fetch({
    url: '/article-comments/star',
    method: 'post',
    needToken: true,
    data
  })
}
export {
  articlesTechnic,
  chartDatHhot,
  articlesShare,
  articlesTechnicTopSearch,
  articlesShareId,
  articlesCommentsId,
  articlesComments,
  articlesCollect,
  articlesStar,
  articleCommentsStar
}
